package com.library.web.controller.library;


import com.library.common.annotation.Log;
import com.library.common.core.controller.BaseController;
import com.library.common.core.domain.AjaxResult;
import com.library.common.core.page.TableDataInfo;
import com.library.common.enums.BusinessType;
import com.library.common.utils.poi.ExcelUtil;
import com.library.domain.BoMembershipGrade;
import com.library.service.IBoMembershipGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 会员等级 信息操作处理
 *
 * @author null
 * @date 2020-04-23
 * @blame Android Team
 */
@RestController
@RequestMapping("/library/boMembershipGrade")
public class BoMembershipGradeController extends BaseController {

    @Autowired
    private IBoMembershipGradeService boMembershipGradeService;

    /**
     * 查询会员等级列表
     */
    @PreAuthorize("@ss.hasPermi('library:boMembershipGrade:list')")
    @GetMapping("/list")
    public TableDataInfo list(BoMembershipGrade boMembershipGrade) {
        startPage();
        List<BoMembershipGrade> list = boMembershipGradeService.selectBoMembershipGradeList(boMembershipGrade);
        return getDataTable(list);
    }

    /**
     * 导出会员等级列表
     */
    @PreAuthorize("@ss.hasPermi('library:boMembershipGrade:export')")
    @Log(title = "会员等级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BoMembershipGrade boMembershipGrade) {
        List<BoMembershipGrade> list = boMembershipGradeService.selectBoMembershipGradeList(boMembershipGrade);
        ExcelUtil<BoMembershipGrade> util = new ExcelUtil<BoMembershipGrade>(BoMembershipGrade.class);
        util.exportExcel(response, list, "会员等级数据");
    }

    /**
     * 获取会员等级详细信息
     */
    @PreAuthorize("@ss.hasPermi('library:boMembershipGrade:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(boMembershipGradeService.selectBoMembershipGradeById(id));
    }

    /**
     * 新增会员等级
     */
    @PreAuthorize("@ss.hasPermi('library:boMembershipGrade:add')")
    @Log(title = "会员等级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BoMembershipGrade boMembershipGrade) {
        return toAjax(boMembershipGradeService.insertBoMembershipGrade(boMembershipGrade));
    }

    /**
     * 修改会员等级
     */
    @PreAuthorize("@ss.hasPermi('library:boMembershipGrade:edit')")
    @Log(title = "会员等级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BoMembershipGrade boMembershipGrade) {
        return toAjax(boMembershipGradeService.updateBoMembershipGrade(boMembershipGrade));
    }

    /**
     * 删除会员等级
     */
    @PreAuthorize("@ss.hasPermi('library:boMembershipGrade:remove')")
    @Log(title = "会员等级", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(boMembershipGradeService.deleteBoMembershipGradeByIds(ids));
    }
}
